import React, { useState, useEffect } from 'react'
import { useNavigate } from "react-router-dom";
import { HomeRightList } from "../api/index";
import { StoreDis, StoreItem } from "../utils/index";
import { useDispatch, useSelector } from 'react-redux';
type Props = {}

const HomeRightTab = (props: Props) => {
    const navigate = useNavigate();
    const discth: StoreDis = useDispatch();
  useEffect(() => {
    getdata();
  }, []);

  const getdata = () => {
    HomeRightList().then((res: any) => {
      discth({
        type: "HOMERIGHTLIST",
        payload: res.data.data,
      });
      console.log(res.data.data);
      
    });
  };
    //从仓库获取数据
    const list = useSelector((store: any) => store.store.HomeRightListdata);
    console.log(list);
    
  return (
    <div>
        {
            list && list.map((item:any,index:number)=>{
              return <span key={index} onClick={()=>navigate("/home/HomeRightTabDetail/"+item.id, { state: item })}>
                {item.label}[{item.articleCount}]
              </span>
            },
            )}
    </div>
  )
}

export default HomeRightTab